import { deepClone, uuid } from "@/utils";
export const sourceType = [
    {
        label: "PC-职业资格",
        value: "PcZhiYe"
    },
    {
        label: "PC-高教题库",
        value: "PcGjtk"
    },
    {
        label: "维普考试APP-职业资格",
        value: "AppZhiYe"
    },
    {
        label: "维普考试APP-高教题库",
        value: "AppGjtk"
    },
    // {
    //     label: "维普职业考试题库APP",
    //     value: "WpZhiYeApp"
    // },
    {
        label: "维普掌上题库(微信端)-职业资格",
        value: "WpZSZhiYe"
    },
    {
        label: "维普掌上题库(微信端)-高教题库",
        value: "WpZSGjtk"
    }
];
export function tableRow2ChildrenList(parent, tableRow, types) {
    var data = deepClone(tableRow);
    return sourceType
        .filter(v => !types || types.includes(v.value))
        .map(t => {
            let type = t.value;
            return {
                accessLog: data.accessLog[type],
                useLog: data.useLog[type],
                paperUseLog: data.paperUseLog[type],
                questionUseLog: data.questionUseLog[type],
                registerLogNew: data.registerLogNew[type],
                registerLog: data.registerLog[type],
                timeUseLog: data.timeUseLog[type],
                timeUseLogAvg: data.timeUseLogAvg[type],
                downloadLog: data.downloadLog[type],
                parent,
                id: uuid(64),
                name: t.label
            };
        });
}

export function logFiledSet(vue, tableRow, result) {
    var data = deepClone(result);
    for (let key in data) {
        vue.$set(tableRow, key, data[key].all);
    }
}

export function tableRow2List(tableRow, field) {
    return [
        tableRow.accessLog.all[field],
        tableRow.useLog.all[field],
        tableRow.paperUseLog.all[field],
        tableRow.questionUseLog.all[field],
        tableRow.registerLogNew.all[field],
        tableRow.registerLog.all[field],
        tableRow.timeUseLog.all[field],
        tableRow.timeUseLogAvg.all[field],
        tableRow.downloadLog.all[field]
    ];
}

export function listAddAll(list) {
    let times = Object.keys(list);
    let result = list[times[0]];
    let keys = Object.keys(result);
    for (let i = 1; i < times.length; i++) {
        let time = times[i];
        for (let k of keys) {
            for (let t of [...sourceType.map(v => v.value), "all"]) {
                // if(k==="timeUseLogAvg"){
                //     result[k][t].allCount=list[times[times.length-1]][k][t].allCount
                //     result[k][t].realAllCount=list[times[times.length-1]][k][t].realAllCount
                //     result[k][t].todayCount += list[times[times.length-1]][k][t].todayCount;
                //     result[k][t].realTodayCount += list[times[times.length-1]][k][t].realTodayCount;
                // }else {
                    result[k][t].allCount = Math.max(
                        list[time][k][t].allCount,
                        result[k][t].allCount
                    );
                    result[k][t].realAllCount = Math.max(
                        list[time][k][t].realAllCount,
                        result[k][t].realAllCount
                    );
                    result[k][t].todayCount += list[time][k][t].todayCount;
                    result[k][t].realTodayCount += list[time][k][t].realTodayCount;
                //}
            }
        }
    }
    return result;
}
